package com.dq.comtroller;

import com.dq.vo.R;
import com.dq.vo.param.UserForm;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;

/**
 * @description:
 * @author: webSocket-chat_小强 (QQ:2680825683)
 * @className: UserController
 * @since: 2023/2/8 15:23
 */
@RestController
@RequestMapping("user")
public class UserController {

    /**
     * 模拟登录
     * @param user
     * @return
     */
    @PostMapping("/login")
    public R login (@RequestBody UserForm user){
        if (ObjectUtils.isEmpty(user)){
            return R.error().message("请输入匿名名称");
        }
        return R.ok().message("登录成功");
    }

    /**
     * 获取当前用户Name
     * @param httpSession
     * @return
     */
    @GetMapping("getUserName")
    public String getUserName(HttpSession httpSession){
        String userName = (String) httpSession.getAttribute("user");
        return userName;
    }
}
